<template>
  <div class="header">
    <div>
      <h3 class="header_title">叩丁狼电商运营平台</h3>
    </div>
    <div
      class="icon_show"
      @click="isShow.changeIsCollapse(!isShow.$state.isCollapse)"
    >
      <el-icon color="white" size="20"><IconMenu /></el-icon>
    </div>
    <div class="header_right">
      <el-dropdown @command="commandHandle">
        <span class="el-dropdown-link">
          {{ store.username
          }}<el-icon class="el-icon--right"><arrow-down /></el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="index">首页</el-dropdown-item>
            <el-dropdown-item command="quit">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Menu as IconMenu, ArrowDown } from "@element-plus/icons-vue";
import { showMenu } from "@/store/showMenu";
import { useUserStore } from "@/store";
import { logoutApi } from "@/request/api";
import { ElMessage } from "element-plus";
import router from "@/router";
import { quit } from "@/common";
const store = useUserStore();
const isShow = showMenu();
// console.log(menushow.changeIsCollapse);
const commandHandle = (command: string) => {
  if (command === "index") {
    router.push("/index");
  } else if (command === "quit") {
    quit(
      () => {
        // 登出请求
        logoutApi();
        console.log(logoutApi);
      },
      () => {
        ElMessage.success("退出登录");
      }
    );
    // ElMessage.success("退出登录");
    // router.push("/login");
  }
};
</script>

<style lang="less" scoped>
.header {
  position: relative;
  display: flex;
  align-items: center;
  .header_title {
    display: inline-block;
    padding: 0 20px;
    line-height: 70px;
    font-weight: 400;
    font-size: 24px;
    color: #fff;
  }
  .icon_show {
    line-height: 10px;
  }
  .header_right {
    position: absolute;
    right: 20px;
    :deep(.el-dropdown) {
      color: white;
    }
  }
}
</style>
